package com.zzptc.lhl.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.google.gson.Gson;
import com.zzptc.lhl.myapplication.entity.Cars;
import com.zzptc.lhl.myapplication.service.CarsService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getcarInfo();

    }

    private void getcarInfo() {
        Retrofit r=new Retrofit.Builder()
                .baseUrl("http://www.hnzzsgz.cn:5001/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        CarsService carsService=r.create(CarsService.class);
        Call<Cars> all = carsService.getAll();
        all.enqueue(new Callback<Cars>() {
            @Override
            public void onResponse(Call<Cars> call, Response<Cars> response) {
                Cars cars =response.body();
                Log.d(TAG, "onResponse: "+new Gson().toJson(cars));
            }

            @Override
            public void onFailure(Call<Cars> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());
            }
        });
    }
}
